<?php
    session_start();

    $con = mysql_connect("localhost","root","");
            if (!$con)
            {
                die('Could not connect: ' . mysql_error());
            }

    mysql_select_db("progin_171_13509008", $con);
            
    $userDelete=$_GET["userDelete"];
    $idComment=$_GET["id"];
    $id_temp = $_SESSION['id_content'];
    
    $queryDeleteCommentRelation = ("delete user_comment from user_comment where id_comment = $idComment");
    $queryDelete = ("delete comment from comment where id_comment = $idComment");

    
    mysql_query($queryDeleteCommentRelation);
    mysql_query($queryDelete);

    // id Content nanti diubah pake session dari user
    $queryGetTotalComment = "select count(id_comment) as totalComment  from comment where id_content=$id_temp";
    $resultTotalComment = mysql_query($queryGetTotalComment);
    while ($rowTotal = mysql_fetch_array($resultTotalComment)){
        echo "<h3 id=\"totalComment\">Total Comment : ".$rowTotal['totalComment']."</h3>";
    }
    
    $querySelectComment = "select id_comment,user_name, comment_text, Concat ( Floor(Hour(TIMEDIFF (comment_time, now()))/24), ' days ',
                                               MOD(HOUR(TIMEDIFF(comment_time, now())), 24), ' hours ',
                                               MINUTE (TIMEDIFF(comment_time, now())), ' minutes')as time from
    comment natural join user_comment where comment.id_content = $id_temp order by time";
    $resultGetComment = mysql_query($querySelectComment);
    
    while ($rowComment = mysql_fetch_array($resultGetComment)){
        echo '<div class="comment_list">';
        echo "<img src='images/avatar/like_button.jpg' width='50px' height='50px' style='float: left;'></img>";
        echo "<button type='button' onclick='deleteComment(\"".$userDelete."\",".$rowComment['id_comment'].")' style='float: right;'>X</button>";
        echo '<h5>'.$rowComment['user_name'].'</h5><br/>';
        echo '<h5>'.$rowComment['time'].'</h5><br/>';
        echo '<h3>'.$rowComment['comment_text'].'</h3>';
        echo '</div>';
    }

?>